<extend name="common:base" />
<block name="body">

    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-6" style='width: 100%'>
                <div class="ibox">
                    <div class="ibox-title">
                        <h5>产品管理</h5>
                        <php>if($auth->check( 'admin/shopproduct/add',  session('uid') )){</php>
                        <a href="{:U('admin/shopproduct/add')}" class="btn btn-info btn-xs" style='margin-left: 20px'>添加</a>
                        <php>}</php>
                        <php>if($auth->check( 'admin/shopproduct/del_many',  session('uid') )){</php>
                        <a href="javascript:void(0)" onclick="confirm_del_many()" class="btn btn-danger btn-xs" style='margin-left: 20px'>删除</a>
                        <php>}</php>
                    </div>

                    <div class="ibox-content">

                        <form role="form" name="searchform" method="get" class="form-inline" >
                            <div class="form-group">
                                <label >产品名称</label>
                                <input class="form-control" type="text" name="name" value="{$search.name}">
                            </div>
                            <div class="form-group">
                                <label >产品分类</label>
                                <select name="typeid" id="" class="form-control">
                                    <option value="0">请选择</option>
                                    <volist name="types" id="vo" >
                                    <option value="{$vo.id}" <if condition="$vo.id eq $search.typeid ">selected</if>>{$vo.typename}</option>
                                    </volist>
                                </select>
                            </div>

                            <div class="form-group">
                                <button type="submit" class="btn btn-outline btn-success" >搜索</button>
                            </div>
                        </form>
                        <p style="line-height: 10px;"></p>
                        <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead>
                            <tr>
                                <th><input type="checkbox" onclick="checkAll(this)" ></th>
                                <th>id</th>
                                <th>产品名称</th>
                                <th>是否推荐</th>
                                <th>分类</th>
                                <th>所需积分</th>
                                <th>限制人数</th>
                                <th>更新时间</th>
                                <php>if($auth->check( 'admin/shopproduct/update',  session('uid') )||$auth->check( 'admin/shopproduct/del',  session('uid') )){</php>
                                <th>操作</th>
                                <php>}</php>
                            </tr>
                            </thead>
                            <tbody id="formlist">
                            <volist name="data.list" id="vo">
                                <tr class="odd gradeA">
                                    <td><input type="checkbox" name="ids[]" value={$vo.id}></td>
                                    <td>{$vo.id}</td>
                                    <td>{$vo.name}</td>
                                    <td>
                                        <notempty name="vo.is_recommend">
                                            是
                                        <else/>
                                            否
                                        </notempty>
                                    </td>
                                    <td>{:getFieldShow('s_type','typename',array('id'=>$vo['typeid']))}</td>
                                    <td>{$vo.price}</td>
                                    <td>{$vo.max_num}</td>
                                    <td>{$vo.updated_at}</td>
                                    <php>if($auth->check( 'admin/shopproduct/update',  session('uid') )||$auth->check( 'admin/shopproduct/del',  session('uid') )){</php>
                                    <td class="center">
                                        <php>if($auth->check( 'admin/shopproduct/update',  session('uid') )){</php>
                                        <a href="/admin/shopproduct/update?id={$vo.id}" class="badge badge-primary">修改</a>&nbsp;&nbsp;
                                        <php>}</php>
                                        <php>if($auth->check( 'admin/shopproduct/del',  session('uid') )){</php>
                                        <a href="javascript:void(0);" class="badge badge-danger" onclick="confirm_del(this)" data-url="{:u('del')}" data-id="{$vo.id}" data-msg="确定要删除吗">删除</a>&nbsp;&nbsp;
                                        <php>}</php>
                                    </td>
                                    <php>}</php>
                                </tr>
                            </volist>
                            </tbody>
                        </table>
                         </div>
                        <div class="col-lg-12" style="float: none">
                            <div class="pagination" >共{$data.count}条</div>
                            <ul class="pagination" id="page" style="float: right">{$data.page}</ul>
                        </div>
                    </div>
                </div>
            </div>

        </div>

    </div>
    </div>
    <script>
        function confirm_del_many(status){
            var data=checked_data();
            if(data==''){
                msg_url('请选择至少一个产品！')
                return false;
            }else{
                var msg ='确定删除吗？';
                layer.confirm(msg, {
                            btn: ['确定','取消'], //按钮
                        }, function(index){
                            $.post("{:U('admin/shopproduct/del_many')}", {"ids":data},
                                    function(data){
                                        msg_url(data.info);
                                        if(data.status==1){
                                            window.setTimeout("location.reload()",1000);
                                        }
                                    }, "json");
                            layer.close(index);
                        }
                );
            }
        }

        function checkAll(t,tname){
            tname = tname?tname:'ids[]';
            var tcheck = $(t).is(':checked');
            $("input[name='"+tname+"']").prop('checked', tcheck);
        }

        function checked_data(){
            var data= $("#formlist").find("input:checked").map(function(index,elem) {
                return $(elem).val();
            }).get().join(',');
            return data;
        }
    </script>
</block>


